﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Toast : MonoBehaviour {
    public Text showText;
    static Toast instance;
    private void Awake()
    {
        instance = this;
        GetComponent<Canvas>().enabled = false;

    }
    /// <summary>
    /// 按照给定的字串显示一个toast
    /// </summary>
    /// <param name="time"></param>
    /// <param name="text"></param>
    public static void Show(float time,string text)
    {
        instance.StartCoroutine(instance.ShowCor(time,text));
    }
    public static void Show(string text)
    {
        Show(1, text);
    }
    IEnumerator ShowCor(float time,string text)
    {
        GetComponent<Canvas>().enabled = true;
        showText.text = text;
        yield return new WaitForSeconds(time);
        GetComponent<Canvas>().enabled = false;


    }

}
